<template>
  <div id="app">
    <div>app组件 - {{ count }} - <button @click="handleClick">btn</button></div>
    <ChildView1 />
    <ChildView2 />
    <ChildView3 />
  </div>
</template>

<script>
import { mapActions } from "vuex";

import ChildView1 from "./views/ChildView1.vue";
import ChildView2 from "./views/ChildView2.vue";
import ChildView3 from "./views/ChildView3.vue";
export default {
  name: "App",
  // data() {
  //   return {
  //     // this.$store表示全局的store实例
  //     count: this.$store.state.count,
  //   };
  // },

  // 为了能够拿到仓库的数据，并且需要有响应式, 需要使用计算属性
  computed: {
    count() {
      return this.$store.state.count;
    },
  },

  methods: {
    // 将actions里面的addAsync函数映射到组件的this.addAsync里面
    ...mapActions(["addAsync"]),
    handleClick() {
      // this.$store.state.count++;

      // 去调用mutations里面的add函数
      // this.$store.commit("add");

      // 去调用actions里面的addAsync函数
      // this.$store.dispatch("addAsync", { a: 3 });
      this.addAsync({ a: 3 });
    },
  },

  components: {
    ChildView1,
    ChildView2,
    ChildView3,
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
